package com.horay.statemachiedemo.multi.persist.config;

import com.horay.statemachiedemo.multi.enums.OrderState;
import com.horay.statemachiedemo.multi.event.OrderEvent;
import com.horay.statemachiedemo.multi.model.Order;
import com.horay.statemachiedemo.multi.persist.OrderDbStateMachinePersist;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.persist.DefaultStateMachinePersister;
import org.springframework.statemachine.persist.StateMachinePersister;

/**
 * Class description
 *
 * @author heyingcheng
 * @date 2020/10/23
 */
@Configuration("orderDbPersistConfig")
public class OrderDbPersistConfig {

    private final OrderDbStateMachinePersist orderDbStateMachinePersist;

    public OrderDbPersistConfig(OrderDbStateMachinePersist orderDbStateMachinePersist) {
        this.orderDbStateMachinePersist = orderDbStateMachinePersist;
    }

    @Bean
    public StateMachinePersister<OrderState, OrderEvent, Order> orderDbStateMachinePersister() {
        return new DefaultStateMachinePersister<>(orderDbStateMachinePersist);
    }

}
